﻿using CongregacaoOs.Business;
using CongregacaoOs.Data;
using DotNet.Highcharts;
using DotNet.Highcharts.Enums;
using DotNet.Highcharts.Options;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Providers.Entities;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Media;
using DotNet.Highcharts.Options;

namespace CongregacaoOs.WebForm.Cadastros
{
    public partial class Home : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["DadosGerais"] == null) Response.Redirect("~/Cadastros/Account/Login.aspx");
            ChartRefhresh();

        }

        public void ChartRefhresh()
        {

            ccReports r = new ccReports();
            List<GetStatistics1_Result> result;


            #region Concluídas
            CreatingConcludedOS();

            #endregion

            #region Em andamento
            result = r.GetStatistics(1); //Andamento

            #endregion

            #region Aguardando
            //result = r.GetStatistics(0); //Aguardando

            #endregion

        }

        public void CreatingConcludedOS()
        {
            try
            {

                using (ccReports r = new ccReports())
                {
                    List<GetStatistics1_Result> lista = r.GetStatistics(2);
                    int count = Convert.ToInt32(lista.Count);

                    string[] lAdms = new string[count];
                    object[] lQtd = new object[count];


                    for (int i = 0; i < count; i++)
                    {
                        lAdms[i] = lista[i].admOut;
                        lQtd[i] = lista[i].qtd;
                    }



                    Highcharts grafico = new Highcharts("chart")
                   .InitChart(new Chart
                   {
                       DefaultSeriesType = ChartTypes.Column,
                       Style = "margin: '0 auto'"
                   })
                   .SetTitle(new Title { Text = "Ordens de Serviço Concluidas por Administração" })
                   .SetSubtitle(new Subtitle { Text = "GPRPO" })
                   .SetXAxis(new XAxis { Categories = lAdms }) //Informações do Eixo X Desta forma Funciona                

                   .SetPlotOptions(new PlotOptions
                   {
                       Bar = new DotNet.Highcharts.Options.PlotOptionsBar
                       {
                           AllowPointSelect = true,
                           Cursor = Cursors.Auto
                       }
                   })
                   .SetYAxis(new YAxis
                   {
                       Min = 0,
                       Title = new YAxisTitle { Text = "Ordens de Serviço" }
                   })
                   .SetLegend(new Legend
                   {
                       Layout = Layouts.Vertical,
                       Align = HorizontalAligns.Left,
                       VerticalAlign = VerticalAligns.Top,
                       X = 100,
                       Y = 50,
                       Floating = true
                   })
                   .SetPlotOptions(new PlotOptions
                   {
                       Column = new DotNet.Highcharts.Options.PlotOptionsColumn
                       {
                           PointPadding = 0.2,
                           BorderWidth = 0
                           //DataLabels = new DotNet.Highcharts.Options.PlotOptionsColumnDataLabels { 
                           //    Enabled=true
                           //},
                           //PointWidth = 1
                       }

                   });

                    grafico.SetSeries(new[]
                    {
                        new Series {Name="Quantidade", Data = new DotNet.Highcharts.Helpers.Data(lQtd)}
                    });

                    ltChart.Text = grafico.ToHtmlString();
                    ltChart.DataBind();

                }
            }
            catch (Exception erro)
            {

                throw new Exception("Message:" + erro.Message);
            }
        }

    }
}